package summer.tree;

public class Solution112 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        return backtracking(root, targetSum);
    }

    public boolean backtracking(TreeNode root, int num) {
        if (root == null) return false;
        num -= root.val;
        if (num == 0) {
            if (root.right == null && root.left == null) return true;
        }
        return backtracking(root.left, num) || backtracking(root.right, num);
    }
}
